package com.xindz.hgq.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.blankj.utilcode.util.ToastUtils;
import com.orhanobut.logger.Logger;
import com.xindz.hgq.R;
import com.xindz.hgq.base.BaseFragment;
import com.xindz.hgq.base.LazyLoadInterface;
import com.xindz.hgq.base.options.BaseFragmentOptions;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * @name HGQBase
 * @class name：com.xindz.hgq.fragment
 * @describe describe
 * @anthor XINDZ
 * @time 2018/1/16 13:45
 * @change
 * @chang time
 * @class describe
 */
public class LazyFragment extends BaseFragment implements LazyLoadInterface {

    @BindView(R.id.bt_frag_show)
    Button btFragShow;
    Unbinder unbinder;
    private String data;

    public LazyFragment() {

    }

    public static LazyFragment newInstance(String msg) {
        LazyFragment lazyFragment = new LazyFragment();
        Bundle bundle = new Bundle();
        bundle.putString("DATA", msg);
        lazyFragment.setArguments(bundle);
        return lazyFragment;
    }

    @Override
    public BaseFragmentOptions setOption() {
        return new BaseFragmentOptions().openLazyLoading(this);
    }

    @Override
    public int onCreateFragmentLayoutId() {
        return R.layout.fragment_frag_lazy;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        data = getArguments().getString("DATA");
        if (data != null) btFragShow.setText("第 " + data + "    FRAGMENT");
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.bt_frag_show)
    public void onViewClicked() {
        ToastUtils.showShort("第 " + data + "    FRAGMENT");
    }

    @Override
    public void onUserFirstVisible() {
        Logger.i("LAZY  onUserFirstVisible:" + data);
    }


    @Override
    public void onUserVisiible() {
        Logger.i("LAZY  onUserVisiible:" + data);
    }

    @Override
    public void onUserInVisiible() {
        Logger.i("LAZY  onUserInVisiible:" + data);
    }
}
